<?php
class TurnosController extends AppController
{
    public $name= 'Turnos';
    public $uses= array('Turno','Gestione');
    public $layout= 'colegio';

    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow('*');
    }
    public function index()
    {
        $turnos=$this->Turno->find('all');
        $this->set(compact('turnos'));
    }
    public function insertar()
    {
        if(!empty($this->request->data))
        {
            $this->Turno->create();
            if($this->Turno->save($this->data))
            {
                $this->Session->setFlash('Turno registrado con Exito','msgbueno');
                $this->redirect(array('action'=>'index'));
            }
            else
            {
                $this->Session->setFlash('No se puedo registrar el Turno');
            }
        }
        $gestiones = $this->Gestione->find('all', array(
           'order'=>array('Gestione.nombre'),
           'recursive'=>-1
        ));
        $this->set(compact('gestiones'));
    }
    public function editar($id=null)
    {
        $this->Turno->id=$id;
            if(!$id)
            {
                $this->Session->setFlash('No existe el Turno');
                $this->redirect(array('action'=>'index'));
            }
            if(empty($this->request->data))
            {
                $this->data=$this->Turno->read();
            }
                else
                {
                    if($this->Turno->save($this->data))
                    {
                        $this->Session->setFlash('Los datos fueron modificados','msgbueno');
                        $this->redirect(array('action'=>'index'));
                    }
                    else
                    {
                        $this->Session->setFlash('no se puedo modificar');    
                    }
                }
        $gestiones = $this->Gestione->find('all', array(
           'order'=>array('Gestione.nombre'),
           'recursive'=>-1
        ));
        $this->set(compact('gestiones'));
    }
    public function eliminar($id=null)
    {
        $this->Turno->id=$id;
        $this->data=$this->Turno->read();
            if(!$id)
             {
                $this->Session->setFlash('No existe el turno a eliminar');
                $this->redirect(array('action'=>'index'));
             }
                else
                {
                    if($this->Turno->delete($id))
                    {
                        $this->Session->setFlash('Se elimino el Turno'.$this->data['Turno']['nombre']);
                        $this->redirect(array('action'=>'index'));
                    }
                    else
                    {
                        $this->Session->setFlash('error al Eliminar');
                    }
                }
    }
    
}
?>